<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class ProductSaleDay extends Model
{
    //
    protected $table = 'product_sale_days';

    protected $fillable = [
        'product_id', 'sale_count', 'total_amount', 'date', 'product_name'
    ];

    public function scopeDate($query, $date) {
        if(!empty($date)) {
            return $query->where('date', $date);
        }
        return $query;
    }

    public function scopeDateFrom($query, $dateStart, $dateEnd) {
        return $query->where('date', '>=', $dateStart)->where('date', '<=', $dateEnd);
    }


    public function scopeProductId($query, $product_id) {
        if(!empty($product_id)) {
            return $query->where('product_id', $product_id);
        }
        return $query;
    }

    public function product() {
        return $this->belongsTo('\App\Model\Product');
    }
}
